package com.qd.common.sys.domain.entity.meun;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.qd.common.sys.domain.entity.role.RoleDTO;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author sjk
 * 菜单
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class MenuDTO extends BaseQuery {
    @JsonIgnore
    @ExcelIgnore
    private static final String EXCEL_TITLE="菜单信息";
    /**
     * 主键
     */
    @ExcelProperty(value = {EXCEL_TITLE, "菜单ID"})
    @NotBlank(message = "菜单ID不能为空", groups = {UpdateGroup.class})
    @Size(max = 50, message = "菜单ID长度不能超过{max}位", groups = {DefaultGroup.class, UpdateGroup.class})
    private String menuId;
    /**
     * 父级菜单ID
     */
    @ExcelProperty(value = {EXCEL_TITLE,"父级菜单ID"})
    @Size(max = 50, message = "父级菜单ID长度不能超过{max}位",groups = DefaultGroup.class)
    private String parentId;
    /**
     * 父级菜单名字
     */
    @ExcelIgnore
    private String parentIdDisplay;
    /**
     * 菜单编码
     */
    @ExcelProperty(value = {EXCEL_TITLE,"菜单编码"})
    @NotBlank(message = "菜单编码不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "菜单编码长度不能超过{max}位",groups = DefaultGroup.class)
    private String menuCode;
    /**
     * 菜单名称
     */
    @ExcelProperty(value = {EXCEL_TITLE,"菜单名称"})
    @NotBlank(message = "菜单名称不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "菜单名称长度不能超过{max}位",groups = DefaultGroup.class)
    private String menuName;
    /**
     * 显示顺序
     */
    @ExcelProperty(value = {EXCEL_TITLE,"显示顺序"})
    private Integer orderNum;
    /**
     * 菜单URL
     */
    @ExcelProperty(value = {EXCEL_TITLE,"菜单URL"})
    @Size(max = 100, message = "菜单URL长度不能超过{max}位",groups = DefaultGroup.class)
    private String menuUrl;
    /**
     * 菜单图标
     */
    @ExcelProperty(value = {EXCEL_TITLE,"菜单图标"})
    @Size(max = 100, message = "菜单图标长度不能超过{max}位",groups = DefaultGroup.class)
    private String menuIcon;
    /**
     * 菜单状态:0正常 1停用
     */
    @ExcelIgnore
    private Integer menuStatus;
    /**
     * 菜单状态显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE,"菜单状态"})
    private String menuStatusDisplay;
    /**
     * 权限标识
     */
    @ExcelProperty(value = {EXCEL_TITLE,"权限标识"})
    @Size(max = 200, message = "权限标识长度不能超过{max}位",groups = DefaultGroup.class)
    private String perms;
    /**
     * 组件路径
     */
    @ExcelProperty(value = {EXCEL_TITLE,"组件路径"})
    @Size(max = 100, message = "组件路径长度不能超过{max}位",groups = DefaultGroup.class)
    private String component;
    /**
     * 菜单类型
     */
    @ExcelIgnore
    @NotBlank(message = "菜单类型不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "菜单类型长度不能超过{max}位",groups = DefaultGroup.class)
    private String menuType;
    /**
     * 菜单类型显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE,"菜单类型"})
    private String menuTypeDisplay;
    /**
     * 显示状态
     */
    @ExcelIgnore
    @Size(max = 20, message = "显示状态长度不能超过{max}位",groups = DefaultGroup.class)
    private String visible;
    /**
     * 显示状态值
     */
    @ExcelProperty(value = {EXCEL_TITLE,"显示状态"})
    private String visibleDisplay;
    /**
     * 是否外链
     */
    @ExcelIgnore
    @Size(max = 20, message = "是否外链长度不能超过{max}位",groups = DefaultGroup.class)
    private String isFrame;
    /**
     * 是否外链显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE,"是否外链"})
    private String isFrameDisplay;
    /**
     * 按钮类型
     */
    @ExcelIgnore
    private String buttonType;
    /**
     * 按钮类型显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE,"按钮类型"})
    private String buttonTypeDisplay;
    /**
     * 添加时间
     */
    @ExcelProperty(value = {EXCEL_TITLE,"添加时间"})
    private LocalDateTime addTime;
    /**
     * 更新时间
     */
    @ExcelProperty(value = {EXCEL_TITLE,"更新时间"})
    private LocalDateTime updateTime;
    /**
     * 子菜单
     */
    @ExcelIgnore
    private List<MenuDTO> children;
    /**
     * 扩展字段，预留
     */
    @ExcelProperty(value = {EXCEL_TITLE,"扩展字段"})
    private String extendedField;

    /**
     * 角色列表
     * 只包含ID和名字
     */
    @ExcelIgnore
    private List<RoleDTO> roleList;

    @Override
    public void freeData() {
        this.menuId = null;
        this.parentId = null;
        this.parentIdDisplay = null;
        this.menuCode = null;
        this.menuName = null;
        this.orderNum = null;
        this.menuUrl = null;
        this.menuIcon = null;
        this.menuStatus = null;
        this.menuStatusDisplay = null;
        this.perms = null;
        this.component = null;
        this.addTime = null;
        this.updateTime = null;
        this.menuType = null;
        this.menuTypeDisplay = null;
        this.visible = null;
        this.visibleDisplay = null;
        this.isFrame = null;
        this.isFrameDisplay = null;
        this.buttonType = null;
        this.buttonTypeDisplay = null;
        if (null != children) {
            children.clear();
        }
        if(null !=roleList){
            roleList.clear();
        }
        this.extendedField = null;
        super.freeData();
    }
}